<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.io.*,java.util.*,java.net.*,com.sino.tb.*,java.sql.*,xpubbean.Db.*"%>
<%@ page errorPage="/pub/errorPage.jsp"%>
<jsp:useBean id="genHandle" scope="session" class="com.sino.tb.genHandle" />
<jsp:useBean id="tools" scope="page" class="com.sino.tb.Tools" />
<%
ServletOutputStream outFile = response.getOutputStream();
int intLength = 0;
String strFileName = "";
File objFile = null;
FileInputStream objFileInputStream = null;
byte[] byteBuffer = new byte[1024];

//String FilePath=genHandle.getUploadPath();
strFileName=request.getParameter("filepath");
if(tools.IsEmpty(strFileName)){
    ResultSetPlus rsTemp = null;
    boolean falgSelect = false;
    Connection con = genHandle.getConnection();
    String c_accessory_id = request.getParameter("c_accessory_id");
    String c_key_value = request.getParameter("c_key_value");
    String c_seq = request.getParameter("c_seq");
    String strSql = "select t.c_seq,t.c_rsp_seq,t.c_accessory_id,t.c_data_path from t_upload_accessory t where t.c_sys_flag = 1 ";

    if(!tools.IsEmpty(c_seq)){
	falgSelect = true;
	strSql += " and t.c_seq = " + c_seq;
    } else  if(!tools.IsEmpty(c_key_value)){
	falgSelect = true;
	strSql += " and t.c_key_value = " + c_key_value;
	if(!tools.IsEmpty(c_accessory_id)){
	    strSql += " and t.c_accessory_id = " + c_accessory_id;
	}
    }
    if (falgSelect){
    	strSql += " order by t.c_seq";
    	rsTemp = new ResultSetPlus(strSql, con);
    	if (rsTemp.next()){
		strFileName = rsTemp.getFieldStr("c_data_path");
    	}
    	rsTemp.close();
    	con.close();
    }
}

com.sino.tb.secMgr.LoginController.println(strFileName);
if(!tools.IsEmpty(strFileName)){
	//objFile = new File(FilePath + strFileName);
	objFile = new File(strFileName);

	if (objFile.exists()){
	    response.reset();
	    response.setContentType("image/jpg");

	    objFileInputStream = new FileInputStream(objFile);
	    while((intLength = objFileInputStream.read(byteBuffer)) != -1){
	    	outFile.write(byteBuffer,0,intLength);
	    }
	    response.flushBuffer();
	    objFileInputStream.close();
	}
}
%>
